import JSEncrypt from 'jsencrypt'

//密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANqwKJSG2kGnweiFe5p89715JvhhqNz5\n' +
    '4q0CINIGTDSFwMVvrQ3EsgbcGasp2TvxtiqeynTpStYfvl+/IbrtrgkCAwEAAQ=='

const privateKey = 'MIIBVwIBADANBgkqhkiG9w0BAQEFAASCAUEwggE9AgEAAkEA2rAolIbaQafB6IV7\n' +
    'mnz3vXkm+GGo3PnirQIg0gZMNIXAxW+tDcSyBtwZqynZO/G2Kp7KdOlK1h++X78h\n' +
    'uu2uCQIDAQABAkEAr4CeIIyUzgoGmUe+qX3PCDUZbE5byXOVUckac9LwB1kwPx0R\n' +
    'Is+L5iVKcB0q2IJRPH2/c9n/cvMzbhS96Rqt/QIhAPGPIDPjFri03wPWGm23hzzH\n' +
    'IPWyCi/fY20rm4bu7NOXAiEA58MCpnLV0Jnq+cyN0P54OI0ZFhablqExbLF6bJnv\n' +
    'P18CIQCYieIzAd8ySn1eJdDQogmTdse4f3JxYqadpOD0p2IEBwIhALtKyv98WfJE\n' +
    'ELJiblDw9HKvBBDnoEDwbyKpoofVNpT9AiEApcBRyGI0mQ+jaIXKPLh+lJSlsfPx\n' +
    'KhfsLQzcYzJzPdM='

// 加密
export function encrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPublicKey(publicKey) //设置公钥return
    return encryptor.encrypt(txt)//对数据进行加密
}

//解密
export function decrypt(txt) {
    const encryptor = new JSEncrypt()
    encryptor.setPrivateKey(privateKey)//设置私钥
    return encryptor.decrypt(txt)//对数据进行解密
}